package my.union;

/**
 * Quick Union - 基于rank的优化 - 路径减半(Path Halving)
 *
 * @author AJun
 * @date 2020/11/1
 */
public class UnionFind_QU_R_PH extends UnionFind_QU_R {

    public UnionFind_QU_R_PH(int capacity) {
        super(capacity);
    }

    @Override
    public int find(int v) {
        rangeCheck(v);
        while (v != parents[v]) {
            parents[v] = parents[parents[v]];
            v = parents[v];
        }
        return v;
    }

}
